import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import qs from 'qs'
import 'font-awesome/css/font-awesome.min.css'

import{
  getCurDate,
  setSessionStorage,
  getSessionStorage,
  removeSessionStorage,
  setLocalStorage,
  getLocalStorage,
  removeLocalStorage
} from './common.js'

axios.defaults.baseURL='http://localhost:8080/elm_servlet'
//允许AXJX发送cookie
axios.defaults.withCredentials = true;

Vue.prototype.$axios = axios;
Vue.prototype.$qs = qs;
Vue.prototype.$getCurDate = getCurDate;
Vue.prototype.$setSessionStorage = setSessionStorage;
Vue.prototype.$getSessionStorage = getSessionStorage;
Vue.prototype.$removeSessionStorage = removeSessionStorage;
Vue.prototype.$setLocalStorage = setLocalStorage;
Vue.prototype.$getLocalStorage = getLocalStorage;
Vue.prototype.$removeLocalStorage = removeLocalStorage;

let arr = ['/','/home','/login','/register','/businesslist','/businessinfo']
router.beforeEach(function(to, from, next){
  let user = getSessionStorage("user");
  if (arr.join(',').indexOf(to.path)>-1) {
    //是不需要拦截的路径
    next();
  }else{
    if (user == null) {
      //跳转到登录页
      router.push('/login')
    }else{
      next()
    }
  }
})

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
